﻿//fs
//#version 330 core

uniform vec3 halfVector;
uniform float shiness = 6;
uniform float strength = 1;
uniform vec3 lightDirection; // direction towards light source in view space
uniform vec3 lightColor;
uniform vec3 diffuseColor = vec3(1, 0.8431, 0); // diffuse color of surface
uniform vec3 ambientColor = vec3(0.2, 0.2, 0.2);

// inputs from vertex shader
smooth in vec3 eyeSpaceNormal; // interpolated normal in eye space

layout(location = 0) out vec4 outColor; // fargment shader output

void main() {
    vec3 L = normalize(lightDirection); // light vector

    float diffuse = max(0, dot(normalize(eyeSpaceNormal), L));
    float specular = 0;
    if (diffuse > 0) {
        specular = max(0, dot(normalize(halfVector), eyeSpaceNormal));
        specular = pow(specular, shiness) * strength;
    }

    outColor = vec4(((ambientColor + diffuse) * diffuseColor + specular) * lightColor, 1.0);
}